;;; guix.scm --- Guix package for texi-docstring-magic

;; Copyright © 2018 Jelle Licht <jlicht@fsfe.org>

;; This file is part of texi-docstring-magic.

;; texi-docstring-magic is free software; you can redistribute it
;; and/or modify it under the terms of the GNU General Public License version 2
;; as published by the Free Software Foundation.
;;
;; texi-docstring-magic is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with texi-docstring-magic.  If not, see
;; <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This file contains Guix package for development version of
;; texi-docstring-magic.  To build or install, run:
;;
;;   guix build --file=guix.scm
;;   guix package --install-from-file=guix.scm

;;; Code:

(use-modules
 (ice-9 popen)
 (ice-9 rdelim)
 (guix build utils)
 (guix build-system emacs)
 (guix gexp)
 (guix licenses)
 (guix git-download)
 (guix packages)
 (gnu packages emacs))

(define %source-dir (dirname (current-filename)))

(define (git-output . args)
  "Execute 'git ARGS ...' command and return its output without trailing
newspace."
  (with-directory-excursion %source-dir
    (let* ((port   (apply open-pipe* OPEN_READ "git" args))
           (output (read-string port)))
      (close-port port)
      (string-trim-right output #\newline))))

(define (current-commit)
  (git-output "log" "-n" "1" "--pretty=format:%H"))

(define emacs-texi-docstring-magic
  (let ((commit (current-commit))
        (revision "0")
        (version "0.1.0"))
    (package
      (name "emacs-texi-docstring-magic")
      (version (string-append version "-" revision "." (string-take commit 7)))
      (source (local-file %source-dir
                          #:recursive? #t
                          #:select? (git-predicate %source-dir)))
      (build-system emacs-build-system)
      (propagated-inputs
       `(("emacs-geiser" ,emacs-geiser)))
      (home-page "https://notabug.org/jlicht/texi-docstring-magic")
      (synopsis "Munge internal docstrings into texi")
      (description "This package generates Texinfo source fragments
from Emacs docstrings.  This avoids documenting functions and
variables in more than one place, and automatically adds Texinfo
markup to docstrings.")
      (license gpl2))))

emacs-texi-docstring-magic

;;; guix.scm ends here
